package com.example.myapplication;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatTextView;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

public class DetailActivity extends AppCompatActivity {
    private AppCompatTextView IpTextview;
    private AppCompatTextView detailedTextview;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_detail);
        super.onCreate(savedInstanceState);

        //实例化控件
        IpTextview = findViewById(R.id.IpTextview);
        detailedTextview = findViewById(R.id.detailedTextview);

        //初始化数据
        String Ip = getIntent().getStringExtra("ip");
        IpTextview.setText(Ip + "");

        String url = "http://whois.pconline.com.cn/ipJson.jsp?ip=" + Ip + "&json=true";
        OkGo.<String>get(url).execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                IpBean ipBean = new Gson().fromJson(response.body(), IpBean.class);
                detailedTextview.setText("省份：");
                detailedTextview.append(ipBean.getPro());
                detailedTextview.append("\n省份编码：");
                detailedTextview.append(ipBean.getProCode());
                detailedTextview.append("\n城市：");
                detailedTextview.append(ipBean.getCity());
                detailedTextview.append("\n城市编码：");
                detailedTextview.append(ipBean.getCityCode());
                detailedTextview.append("\n地址：");
                detailedTextview.append(ipBean.getAddr());


            }
        });


    }

}
